package cn.battlecruiser.vishnu.userinfo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.segments.MergeSegments;
import com.baomidou.mybatisplus.core.injector.methods.SelectByMap;

import cn.battlecruiser.vishnu.userinfo.mapper.UserinfoMapper;
import cn.battlecruiser.vishnu.common.model.Userinfo;


@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserinfoMapper userinfoMapper;
	
	@Autowired
    private DataSource dataSource;
	
	@GetMapping("/info")
    public List<Userinfo> user(Userinfo userVo) {		
		List<Userinfo> userInfo = userinfoMapper.selectList(null);
        return userInfo;
    }
	
	@GetMapping("/findUserByUsername/{username}")
	public Userinfo findUserByUsername(@PathVariable("username") String username){
		Map<String,Object> params = new HashMap<String, Object>();
		params.put("username", username);
		List<Userinfo> result = userinfoMapper.selectByMap(params);
		return result.isEmpty()?null:result.get(0);
	}
}
